<?php
 /**
 * Get Local time and how many user register in current selected time
 * @author: trungdt
 * @since: Mar 8, 2011 
 * @version: 1.0
 * 
 * Change logs
 * 
 */
if (!defined("EXPONENT")) exit("");
    $id=-1;
    if (isset($_REQUEST['fh']))
    {
        $fhour=intval($_REQUEST['fh']);
        $fmin=intval($_REQUEST['fm']);
        $thour=intval($_REQUEST['th']);
        $tmin=intval($_REQUEST['tm']);
        
        // convert from time and to time to check the registration is exist or not
        $ftime=$fhour*60+$fmin;
        $ttime=$thour*60+$tmin;
        $temp=$db->selectObjectsBySql("
        SELECT user_id FROM {$db->prefix}pray_register 
        WHERE
        ((fhour*60+fmin <= {$ftime})
        OR (fhour*60+fmin <= {$ftime} AND {$ttime} <= thour*60+tmin))
        GROUP BY user_id
        ");
        
        
        $ret_obj=null;
        $ret_obj->sum=count($temp);
        $ret_obj->local_time="";
        
        // convert to local time
        $server_belt=7; // set default current server time belt is gmt +7
        global $user;
        
        aboid_localtime_convert($fhour, $fmin, $fhour, $fmin);
        aboid_localtime_convert($thour, $tmin, $thour, $tmin);
        
        // done, then we make time pretty
        $fhour=str_pad($fhour,2,"0",STR_PAD_LEFT);
        $fmin=str_pad($fmin,2,"0",STR_PAD_LEFT);
        $thour=str_pad($thour,2,"0",STR_PAD_LEFT);
        $tmin=str_pad($tmin,2,"0",STR_PAD_LEFT);
        $ret_obj->local_time="{$fhour}:{$fmin} - {$thour}:{$tmin}";
        
        echo json_encode($ret_obj);
    }
?>
